package com.hibase.core.mq.redis.config;

import com.hibase.core.mq.annotation.HibaseQueue;
import com.hibase.core.mq.factory.HandlerFactory;
import com.hibase.core.mq.factory.QueueHandler;
import com.hibase.core.mq.redis.handler.RedisQueueHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenfeng
 * @version 1.0
 * @date 2021/7/15 14:41
 * @des https://gitee.com/cheershi
 */
@Slf4j
@Configuration
public class RedisQueueConfiguration {

    @Bean
    @ConditionalOnClass(QueueHandler.class)
    public QueueHandler redisQueueHandler() throws Exception{

        try {
            QueueHandler queueHandler = new RedisQueueHandler();
            HandlerFactory.INSTANCE.modifyHandlerProperty(HibaseQueue.class,"queueHandler",queueHandler);
            log.info(">>>>>>>>>>>>>>>>>>>>>> Initial RedisQueueHandler Successfully.");
            return queueHandler;
        } catch (Exception e) {
            log.error(">>>>>>>>>>>>>>>>>>>>>> Initial RedisQueueHandler Error.",e);
            throw e;
        }

    }
}
